package com.atguigu.service.impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.DictDao;
import com.atguigu.dao.UserFollowDao;
import com.atguigu.entity.UserFollow;
import com.atguigu.service.DictService;
import com.atguigu.service.UserFollowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class userFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {
    @Autowired
    private UserFollowDao userFollowDao;
    @Autowired
    private DictDao dictDao;
    @Override
    public BaseDao<UserFollow> getBaseDao() {
        return userFollowDao;
    }

    @Override
    public void insertFollow(Long userId, Long houseId) {
        UserFollow userFollow = new UserFollow();
        userFollow.setHouseId(houseId);
        userFollow.setUserId(userId);
        userFollowDao.insert(userFollow);
    }

    @Override
    public UserFollow getByUserIdAndHouseId(Long userId,Long houseId) {
        return userFollowDao.getByUserIdAndHouseId(userId,houseId);
    }

    @Override
    public PageInfo<UserFollowVo> getByUserId(Long userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<UserFollowVo> userFollowVo = userFollowDao.getByUserId(userId);
        for (UserFollowVo followVo : userFollowVo) {
            followVo.setHouseTypeName(dictDao.findById(followVo.getHouseTypeId()).getName());
            followVo.setFloorName(dictDao.findById(followVo.getFloorId()).getName());
            followVo.setDirectionName(dictDao.findById(followVo.getDirectionId()).getName());
        }
        return new PageInfo<>(userFollowVo,2);
    }


}
